<template>
  <div class="loginPage">
    <div class="loginAndRegister">
      <div class="register" v-show="!loginCur">
        <div class="registerBox">
          <div class="Title">注册</div>
          <el-form>
            <div class="items regEmail">
              <div>手机号码/邮箱</div>
              <input type="text" />
            </div>
            <div class="items regPwd">
              <div>密码</div>
              <input type="password" />
            </div>
            <div class="items regPwdAgain">
              <div>确认密码</div>
              <input type="password" />
            </div>
            <div class="checkbox">
              <input class="checkBtn" type="checkbox" />我已经阅读并同意目前的
              隐私政策。
            </div>
            <button class="Btn">注&nbsp册</button>
          </el-form>
          <div class="tips" @click="loginCur = !loginCur">已有账号？去登录</div>
        </div>
      </div>

      <div class="login" v-show="loginCur">
        <div class="loginBox">
          <div class="Title">欢迎登录</div>
          <form :model="form" status-icon>
            <div class="formItem userTxt" prop="username">
              <i class="iconfont icon-zhanghao"></i
              ><input auto-complete="off"
                type="text"
                placeholder="请输入您的账号"
                v-model="form.username"
              />
              </div>
            <div class="formItem userPwd">
              <i class="iconfont icon-mima"></i
              ><input
                type="password"
                placeholder="请输入您的密码"
                v-model="form.password"
              />
              </div>
            <el-button  type="button" class="Btn" @click="login" >登&nbsp录</el-button>
            <div class="tips" @click="loginCur = !loginCur">
              还没有账号？点击注册
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { postLogin } from '@/api'
export default {
  name: 'login',
  data(){
    return{
      loginCur:true,
      form:{}
    }
  },
  methods:{
    async login(){
      const res = await postLogin(this.form)
      if(res.code == 200){
        localStorage.setItem('token',res.data.token)
        localStorage.setItem('nickname',res.data.nickname)
        localStorage.setItem('imgUrl',res.data.imgUrl)
        this.$store.commit('LOGIN',res.data)
        this.$router.push('/home')
        location.reload()
      }else{
        this.$notify({
          type:'warning',
          message: '您输入的账号或密码有误！',
          duration:1000,
          showClose: false
        });
      }
    }
  }
}
</script>

<style lang="less" scoped>
.loginPage {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-image: url(./images/banner4.jpg);
  background-size: 100%;
}
.loginAndRegister {
  width: 50%;
  height: 60%;
  border: 1px solid #333;
  box-shadow: 0px 0px 40px #333;
  background-color: rgba(0, 0, 0, 0.1);
}
input {
  border: none;
  border-bottom: 1px solid #333;
  background: none;
  outline: none;
}

.Btn {
  padding: 9px 0;
  margin-top: 10px;
  background-color: #333;
  color: #fff;
  cursor: pointer;
}
.Title {
  text-align: center;
  font-size: 2.5em;
  padding-top: 68px;
}
.tips {
  font-size: 0.5em;
  cursor: pointer;
}
button {
  width: 100%;
}
.login {
  width: 50%;
  height: 100%;
  background-color: #fff;
  .loginBox {
    width: 80%;
    margin: 0 auto;
    form {
      margin-top: 20px;
      font-size: 1.2em;
      .formItem {
        margin: 30px 5px;
      }
      i {
        width: 10%;
      }
      input {
        width: 90%;
        margin-left: 5px;
      }

      .tips {
        float: right;
      }
    }
  }
}
.register {
  width: 50%;
  height: 100%;
  background-color: #333;
  color: #fff;
  float: right;
  .registerBox {
    width: 80%;
    margin: 0 auto;
    .Title {
      padding-top: 38px;
    }
    form {
      margin-top: 20px;
      font-size: 1.1em;
      .items {
        margin: 20px 0;
      }
      input {
        width: 100%;
        color: #fff;
        border-bottom: 1px solid #fff;
      }
      .checkbox {
        font-size: 0.6em;
        .checkBtn {
          width: 7%;
        }
      }
      .Btn {
        background-color: #fff;
        color: #333;
      }
    }
  }
}
.el-alert{
  position: absolute;
  width: 21%;
  height: 6%;
}
</style>
